From 609a849edd472df0c77e3786d1b63b1e1ad8ad5d Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 30 Aug 2002 14:50:03 +0000 Subject: [PATCH] Hook up the shortname synthesizer to everything else. No more GC1234 names! --- gpsbabel/ChangeLog | 4 ++- gpsbabel/Makefile | 3 ++- gpsbabel/README | 22 ++++++++++++++++- gpsbabel/defs.h | 9 +++++++ gpsbabel/gpsutil.c | 3 ++- gpsbabel/magproto.c | 3 ++- gpsbabel/main.c | 12 +++++++-- gpsbabel/mkshort.c | 59 +++++++++++++++++++++++++++++++++++++++------ gpsbabel/pcx.c | 5 ++-- gpsbabel/waypt.c | 6 +++-- 10 files changed, 108 insertions(+), 18 deletions(-) diff --git a/gpsbabel/ChangeLog b/gpsbabel/ChangeLog index ff0fd40fc..4df26334b 100644 --- a/gpsbabel/ChangeLog +++ b/gpsbabel/ChangeLog @@ -1,5 +1,7 @@ -NEW: blah blah NEW: Add Cetus support. Thanx to Ron Parker and Kjeld Jensen. +NEW: Add gpspilot support. NEW: Windows support. You must download and install the expat dll if you do not already have it. Get it from http://sourceforge.net/projects/mingwrep/ + +FIXED: Bad math in gpsutil. diff --git a/gpsbabel/Makefile b/gpsbabel/Makefile index 207ba839c..fdb0587c5 100644 --- a/gpsbabel/Makefile +++ b/gpsbabel/Makefile @@ -3,7 +3,8 @@ CFLAGS=-g -Icoldsync FMTS=magproto.o gpx.o geo.o gpsman.o mapsend.o mapsource.o \ gpsutil.o tiger.o pcx.o csv.o cetus.o gpspilot.o magnav.o -OBJS=main.o queue.o route.o waypt.o util.o vecs.o coldsync/util.o coldsync/pdb.o $(FMTS) +OBJS=main.o queue.o route.o waypt.o util.o vecs.o mkshort.o \ + coldsync/util.o coldsync/pdb.o $(FMTS) all: gpsbabel diff --git a/gpsbabel/README b/gpsbabel/README index 220988295..9ec0d593f 100644 --- a/gpsbabel/README +++ b/gpsbabel/README @@ -33,7 +33,14 @@ THE FORMATS MAGELLAN - Waypoint upload and download works reliably. + Waypoint serial upload and download works reliably to the 315, 330, + Meridian, and SportTrak family. I expect it to work on any modern + Magellan unit. + + As of 08/30/02, gpsbabel can also read and write the files that + can be stuck on the flash memory parts + +BLAH BLAH BLAH As of this writing, there is still a lot of "scribbling" in the source for functionality that isn't hooked up to the rest of the @@ -78,6 +85,19 @@ THE FORMATS yet, a module that implements it. I spent time trying to reverse- engineer a couple of *.mps files then I remembered that I don't own a Garmin and wasn't that inspired. + + CETUS + + Cetus GPS (http://www.cetusgps.dk/) is a program for Palm/OS. + Working with Ron Parker and Kjeld Jensen, we can now read and write + files for that program. It hasn't been exhaustively tested, but + has seemed fine on every input and output we've tried. + + GPSPILOT + + The file format for GPSPILOT (http://www.gpspilot.com) was provided + by Ron Parker. GPSbabel can currently read gpspilot files, but not + write them. COMMON USAGE diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index fe57a4353..bdc7e0d44 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -30,6 +30,12 @@ * data in this file. */ +typedef struct { + int synthesize_shortnames; +} global_options; + +extern global_options global_opts; + /* * A coordinate in space. */ @@ -86,6 +92,9 @@ void route_add (waypoint *); void waypt_disp_all(waypt_cb); unsigned int waypt_count(void); void fprintdms(FILE *, coord *, int); +char *mkshort (const char *); +void setshort_length(int n); +void setshort_badchars(const char *); typedef struct ff_vecs { ff_init rd_init; diff --git a/gpsbabel/gpsutil.c b/gpsbabel/gpsutil.c index 18a688665..1b046a128 100644 --- a/gpsbabel/gpsutil.c +++ b/gpsbabel/gpsutil.c @@ -89,7 +89,8 @@ gpsutil_disp(waypoint *wpt) lat = wpt->position.latitude.degrees * 100.0; fprintf(file_out, "%-8s %08.3f%c %09.3f%c %07.0f%c %-30.30s %s\n", - wpt->shortname, + global_opts.synthesize_shortnames ? + mkshort(wpt->description) : wpt->shortname, fabs(lat), lat < 0.0 ? 'S' : 'N', fabs(lon), diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index dc226adfa..0b5a64a54 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -737,7 +737,8 @@ mag_waypt_pr(waypoint *waypointp) lat, ilon < 0 ? 'N' : 'S', lon, ilat < 0 ? 'E' : 'W', waypointp->position.altitude.altitude_meters, - waypointp->shortname, + global_opts.synthesize_shortnames ? + mkshort(waypointp->description) : waypointp->shortname, waypointp->description ? waypointp->description : "", icon_token); mag_writemsg(obuf); diff --git a/gpsbabel/main.c b/gpsbabel/main.c index 4288e713d..4ec9cc2d7 100644 --- a/gpsbabel/main.c +++ b/gpsbabel/main.c @@ -20,10 +20,12 @@ #include "defs.h" +global_options global_opts; + void usage(const char *pname) { - printf("Usage: %s -i -f -o -F \n", pname); + printf("Usage: %s [-s] -i -f -o -F \n", pname); printf("Supported file types:\n"); disp_vecs(); } @@ -60,17 +62,19 @@ main(int argc, char *argv[]) c = argv[argn][1]; optarg = argv[argn+1]; - argn++; switch (c) { case 'i': ivecs = find_vec(optarg); + argn++; break; case 'o': ovecs = find_vec(optarg); + argn++; break; case 'f': fname = optarg; + argn++; if (ivecs == NULL) { fatal ("No valid input type specified"); } @@ -79,11 +83,15 @@ main(int argc, char *argv[]) break; case 'F': ofname = optarg; + argn++; if (ovecs) { ovecs->wr_init(ofname); ovecs->write(); } break; + case 's': + global_opts.synthesize_shortnames = 1; + break; case 'h': case '?': usage(argv[0]); diff --git a/gpsbabel/mkshort.c b/gpsbabel/mkshort.c index 5bc6aa8f0..932390c0a 100644 --- a/gpsbabel/mkshort.c +++ b/gpsbabel/mkshort.c @@ -1,14 +1,20 @@ #include -const char badchars[] = "\"$.,'!-"; -const char vowels[] = "aeiouAEIOU"; +static const char vowels[] = "aeiouAEIOU"; -#define TGT_LEN 8 +#define DEFAULT_TARGET_LEN 8 +static int target_len = DEFAULT_TARGET_LEN; + +#define DEFAULT_BADCHARS "\"$.,'!-" +static const char *badchars = DEFAULT_BADCHARS; + +static int mustupper = 0; /* * This is the stuff that makes me ashamed to be a C programmer... */ +static char * delete_last_vowel(int start, char *istring, int *replaced) { @@ -33,6 +39,41 @@ delete_last_vowel(int start, char *istring, int *replaced) } +/* + * Externally callable function to set the max length of the + * strings returned by mkshort(). 0 resets to default. + */ +void +setshort_length(int l) +{ + if (l == 0) { + target_len = DEFAULT_TARGET_LEN; + } else { + target_len = l; + } +} + +/* + * Externally callable function to set the string of characters + * that must never appear in a string returned by mkshort. NULL + * resets to default. + */ +void +setshort_badchars(const char *s) +{ + if (s == NULL) { + badchars = DEFAULT_BADCHARS; + } else { + badchars = strdup(s); + } +} + +void +setshort_mustupper(int i) +{ + mustupper = i; +} + char * mkshort(char *istring) { @@ -88,6 +129,9 @@ mkshort(char *istring) cp = ostring; for (i=0;i TGT_LEN) { + while (replaced && strlen(ostring) > target_len) { ostring = delete_last_vowel(2, ostring, &replaced); } @@ -154,13 +198,13 @@ mkshort(char *istring) * Now brutally truncate the resulting string, preserve trailing * numeric data. */ - if ((i = strlen(ostring)) > TGT_LEN) { - strcpy(&ostring[TGT_LEN] - strlen(np), np); + if ((i = strlen(ostring)) > target_len) { + strcpy(&ostring[target_len] - strlen(np), np); } return ostring; } - +#if 0 char *foo[] = { "VwthPst# 3700.706N 08627.588W 0000000m View the Past #2 ", "PilotRoc 3655.270N 08717.173W 0000000m Pilot Rock by CacheAdvance ", @@ -335,3 +379,4 @@ printf("%s\n", delete_last_vowel(0, "ixxx", &r)); printf("%s\n", delete_last_vowel(0, "aexxx", &r)); } +#endif diff --git a/gpsbabel/pcx.c b/gpsbabel/pcx.c index f65b83ed2..4cffcc017 100644 --- a/gpsbabel/pcx.c +++ b/gpsbabel/pcx.c @@ -114,7 +114,8 @@ gpsutil_disp(waypoint *wpt) } fprintf(file_out, "W %-6.6s %c%08.5f %c%011.5f %s %5d %-40.40s %5e %s\n", - wpt->shortname, + global_opts.synthesize_shortnames ? + mkshort(wpt->description) : wpt->shortname, lat < 0.0 ? 'S' : 'N', fabs(lat), lon < 0.0 ? 'W' : 'E', @@ -140,7 +141,7 @@ fprintf(file_out, "U LAT LON DM\n" "\n" "H IDNT LATITUDE LONGITUDE DATE TIME ALT DESCRIPTION PROXIMITY SYMBOL ;waypts\n"); - + setshort_length(6); waypt_disp_all(gpsutil_disp); } diff --git a/gpsbabel/waypt.c b/gpsbabel/waypt.c index 0e47703c7..71d421ea7 100644 --- a/gpsbabel/waypt.c +++ b/gpsbabel/waypt.c @@ -53,7 +53,8 @@ waypt_disp(waypoint *wpt) printposn(&wpt->position.latitude,1); printposn(&wpt->position.longitude,0); printf("%s/%s %f\n", - wpt->shortname, + global_opts.synthesize_shortnames ? + mkshort(wpt->description) : wpt->shortname, wpt->description, wpt->position.altitude.altitude_meters); } @@ -63,7 +64,8 @@ waypt_disp_all(waypt_cb cb) { queue *elem, *tmp; waypoint *waypointp; - +setshort_length(8); +setshort_mustupper(0); QUEUE_FOR_EACH(&waypt_head, elem, tmp) { waypointp = (waypoint *) elem; (*cb) (waypointp); -- 2.30.2